package org.e_gold.dto;


/**
 * @author Thang Nguyen
 */
public class BetRule {

	private int minute;
	private Float rateMin;
	private Float rateMax;
	private Integer goalMin;
	private Integer goalMax;

	public BetRule(String rule) throws Exception{
		//80;1.01;1.07;5;7;
		String[] r = rule.split(";");
		if(r.length != 5){
			throw new Exception("Config part is wrong: " + rule);
		}

		minute = Integer.parseInt(r[0]);
		rateMin = Float.parseFloat(r[1]);
		rateMax = Float.parseFloat(r[2]);
		goalMin = Integer.parseInt(r[3]);
		goalMax = Integer.parseInt(r[4]);
	}

	public Boolean isQualify(int playTime, Float rate, int currentGoal, int totalGoal) {
		//playtime is greater than require
		if(playTime >= minute){
			//rate in range
			if(rateMin <= rate && rate <= rateMax){
				//goalMax = -2, mean different between current and total > 2
				if(goalMax < -1){
					if(currentGoal - totalGoal <= (goalMax)){
						return true;
					}
				}else{
					if(currentGoal <= goalMin){
						//totalGoal may greater or equals with require
						if(goalMax <= totalGoal){
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	public int getMinute() {
		return minute;
	}

	public void setMinute(int minute) {
		this.minute = minute;
	}

	public Float getRateMin() {
		return rateMin;
	}

	public void setRateMin(Float rateMin) {
		this.rateMin = rateMin;
	}

	public Float getRateMax() {
		return rateMax;
	}

	public void setRateMax(Float rateMax) {
		this.rateMax = rateMax;
	}

	public Integer getGoalMin() {
		return goalMin;
	}

	public void setGoalMin(Integer goalMin) {
		this.goalMin = goalMin;
	}

	public Integer getGoalMax() {
		return goalMax;
	}

	public void setGoalMax(Integer goalMax) {
		this.goalMax = goalMax;
	}

}
